package com.app.service.impl;


import com.app.mapper.GraduationStatusMapper;
import com.app.mapper.SchoolMapper;
import com.app.model.GraduationStatusModel;
import com.app.model.SchoolModel;
import com.app.service.GraduationStatusService;
import com.app.service.SchoolService;
import com.app.util.StringTool;
import com.app.vo.GraduationStatusVo;
import com.app.vo.SchoolVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class GraduationStatusImpl implements GraduationStatusService {

    @Resource
    private GraduationStatusMapper graduationStatusMapper;


    @Override
    public GraduationStatusVo bakGetModelList(GraduationStatusModel model) {
        QueryWrapper<GraduationStatusModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("school_id",model.getSchoolId());
        if (StringTool.isNotEmpty(model.getSpeciality())) {
            queryWrapper.like("speciality", model.getSpeciality());
        }
        Page<GraduationStatusModel> pages = new Page<>();
        pages.setCurrent(model.getPage());
        pages.setSize(model.getLimit());
        Page<GraduationStatusModel> page = graduationStatusMapper.selectPage(pages, queryWrapper);
        if (page == null) {
            return null;
        } else {
            GraduationStatusVo vo = new GraduationStatusVo();
            vo.setList(page.getRecords());
            vo.setCount((int)page.getTotal());
            return vo;
        }
    }

    @Override
    public GraduationStatusModel getModelById(Integer id) {
        return graduationStatusMapper.selectById(id);
    }

    @Override
    public Integer insert(GraduationStatusModel model) {
        return graduationStatusMapper.insert(model);
    }

    @Override
    public void update(GraduationStatusModel model) {
        graduationStatusMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        graduationStatusMapper.deleteById(id);
    }
}
